package com.student.foodAfter.service;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * ClassName: SendEmailService <br/>
 * Description: <br/>
 * date: 2023/1/15 19:45<br/>
 *
 * @author 李林雨 <br/>
 * @since JDK 8
 */
@Service("mailService")
public class SendEmailService {
    @Resource
    private JavaMailSender mailSender;

    @Value("${mail.fromMail.addr}")
    private String form;

    /**
     * 发送简单邮件
     * @param to 接受者
     * @param subject 主题
     * @param content 内容
     */
    public void sendMail(String to, String subject, String content) {
        SimpleMailMessage mailMessage=new SimpleMailMessage();
        mailMessage.setFrom(form);
        mailMessage.setTo(to);
        mailMessage.setSubject(subject);
        mailMessage.setText(content);
        try {
            mailSender.send(mailMessage);
//            System.out.println("发送简单邮件");
        }catch (Exception e){
            e.printStackTrace();
//            System.out.println("发送简单邮件失败");
        }
    }
}
